import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver


# 用户管理
class UserManagement:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/user"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetUserManagement(self):
        # 筛选机构
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[1]/div/label/span/input').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div/div[1]/div/div/span/a').click()

        # 按照姓名搜索
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("k大王")
        # 点击搜索
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button/span').click()
        time.sleep(1.5)
        # 截图查看
        QESDriver.GetScreenShot()
        # 点击重置
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button/span').click()

        ################################################################

    def CreateNewUsers(self):
        # 新建
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[1]/button').click()
        # 输入用户名：测试新建用户
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("测试新建用户")
        # 输入登录名：Test
        self.driver.find_element(By.XPATH, '//*[@id="username"]').send_keys("Test")
        # 输入密码：123456
        self.driver.find_element(By.XPATH, '//*[@id="password"]').send_keys("123456")
        # 输入确认密码：123456
        self.driver.find_element(By.XPATH, '//*[@id="rePassword"]').send_keys("123456")
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 批量导入
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[2]/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 编辑用户
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[8]/div/div[1]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()


# 角色管理
class RoleManagement:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/role"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetRoleManagement(self):
        # 查询
        self.driver.find_element(By.CSS_SELECTOR, '#name').send_keys("k小兵")
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()

        # 新建
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入角色信息
        self.driver.find_element(By.CSS_SELECTOR, '#name').send_keys("Test")
        # 输入角色编码
        self.driver.find_element(By.XPATH, '//*[@id="code"]').send_keys("10110")
        # 输入描述
        self.driver.find_element(By.XPATH, '//*[@id="remark"]').send_keys("测试新建角色")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()

        # 编辑角色
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[6]/div/div[1]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()

# 组织机构
class InstitutionalFramework:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/dept"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetInstitutionalFramework(self):
        # 新建操作
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div/div/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()


# 岗位设置
class PostSetting:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/position"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetPostSetting(self):
        # 输入查询
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("k部队")
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        # 新建岗位
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入岗位名称
        self.driver.find_element(By.CSS_SELECTOR, '#name').send_keys("测试新建岗位")
        time.sleep(1.5)
        # 输入岗位编码
        self.driver.find_element(By.XPATH, '//*[@id="code"]').send_keys("1010101")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 编辑岗位
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[4]/div/div[1]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 删除岗位
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[4]/div/div[2]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()


# 字典设置
class Dictionarization:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/dict"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetDictionarization(self):
        # 输入查询
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("k字典")
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        time.sleep(1.5)
        # 新建字典
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div/button').click()
        # 输入字典名称
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("小k字典")
        # 输入字典编码
        self.driver.find_element(By.XPATH, '//*[@id="code"]').send_keys("2222222")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()
        # 字典项
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[2]/td[6]/div/div[1]/a').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()


# 个人设置
class PersonalSettings:
    def __init__(self):
        self.url = "http://8.155.1.153:8081/system/setting"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetPersonalSettings(self):
        # 清空原有的信息
        QESDriver.ClearInput(self.driver.find_element(By.XPATH, '//*[@id="name"]'))
        QESDriver.ClearInput(self.driver.find_element(By.XPATH, '//*[@id="phone"]'))
        QESDriver.ClearInput(self.driver.find_element(By.XPATH, '//*[@id="email"]'))
        QESDriver.ClearInput(self.driver.find_element(By.XPATH, '//*[@id="profile"]'))
        time.sleep(5)
        # 输入新的
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("k小王")
        # 查找输入手机号
        self.driver.find_element(By.XPATH, '//*[@id="phone"]').send_keys("18888888888")
        # 查找输入邮箱
        self.driver.find_element(By.XPATH, '//*[@id="email"]').send_keys("39999999999@qq.com")
        # 查找输入个人简介
        self.driver.find_element(By.XPATH, '//*[@id="profile"]').send_keys("无")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        # 点击提交
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[2]/div[2]/div[1]/form/div[5]/div[2]/button').click()
        # 点击安全设置
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[1]/ul/li[2]/span').click()
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        # 点击修改
        self.driver.find_element(By.XPATH,
                                 '//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div/div/div[2]/div[2]/div/div/ul/li/ul/li/a').click()
        #输入旧密码
        self.driver.find_element(By.XPATH,
                                 '//*[@id="oldPassword"]').send_keys("sss123")
        # 输入新密码
        self.driver.find_element(By.XPATH,
                                 '//*[@id="password"]').send_keys("sss111")
        # 确认新密码
        self.driver.find_element(By.XPATH,
                                 '//*[@id="confirmPassword"]').send_keys("sss111")
        time.sleep(1.5)
        QESDriver.GetScreenShot()
        self.driver.refresh()





